package com.blockmeta.bbs.baselibrary.base.adapter;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;
import java.util.Random;

/**
 * @author AirThor
 * @date 2018/5/24.
 */

public class QuickPagerAdapter<T extends View> extends PagerAdapter {
    private List<T> mList;
    private Context mContext;
    private final Random random = new Random();

    public QuickPagerAdapter(Context context, List<T> list) {
        mList = list;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mList==null?0:mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = mList.get(position);
        container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
